#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include<signal.h>

#define MSGKEY 2222

struct mybuf {
	long mtype;
	char text[100];
};

int main(){
	int qid;
		
	// 创建消息队列 获得qid
	qid = msgget(MSGKEY, IPC_CREAT | 0666);
	if(qid==-1){
		perror("Failed in calling msgget");
		return 0;
	}
	//读文件
	FILE*fp = fopen("data.txt","r");
	// sender		
	int i=0;	
			while(i<10){		
				struct mybuf buf;
				fgets(buf.text, sizeof(buf.text), fp);
				printf("message %d:\t", i);
				printf("%s\n", buf.text);
				buf.mtype = 1000;
				
				msgsnd(qid, &buf, sizeof(buf.text), IPC_NOWAIT);
				i++;
			}
	fclose(fp);

	return 0;
}
